<?php
/**
 * @version 0.8.3 2010-10-07
 * @package Joomla
 * @subpackage LeagueResults
 * @copyright (C)  2008, 2009, 2010 Henryk Drozd
 * @license GNU/GPL, see LICENSE.php
 * LeagueResults is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2
 * as published by the Free Software Foundation.

 * LeagueResults is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
?>

<div class="componentheading">
<?php echo JText::_( 'KNOCKOUT TREE OF THE TOURNAMENT' ); 
?>
</div>

<table class="knockouttree" >
<tr>
	<th colspan="<?php $levels=count($this->tree);echo pow(2, $levels);?>">
	<?php echo JText::_( 'SEASON' ).': '.$this->list[0]->name.' '.$this->list[0]->year?>
	</th>
</tr>
<?php if (JRequest::getVar('view_t') == 'vertical') { ?>
		<?php for($i=count($this->tree)-1;$i>=0;$i--){ ?>
		<tr>
			<?php for($j=0;$j<=count($this->tree[$i])-1;$j++){
					 $match = $this->tree[$i][$j]; ?>
			<?php if (($match->results_quantity > 0)&&(JRequest::getVar('displayresults') == 'yes')) {
				if ($match->hscore > $match->vscore)
					$match->hteam = '<span class="wteam">'.$match->hteam.'</span>';
				if ($match->vscore > $match->hscore)
					$match->vteam = '<span class="wteam">'.$match->vteam.'</span>';
				if ($match->vscore == $match->hscore){
					$match->vteam = '<span class="draw">'.$match->vteam.'</span>';
					$match->hteam = '<span class="draw">'.$match->hteam.'</span>';
					}
				}
				?>
			<td colspan="<?php echo pow(2, $levels-$i);?>"><div style="text-align:center;">
			<?php echo $match->formattedmatchdate; ?><br/>
			
		<?php switch (JRequest::getVar('links_ondisplay')){ 
				case 'none':
				default:
					echo $match->hteam;
					break;
				case 'team':
			?>
			    	<a href="<?php echo $match->hlink; ?>">
		        	<?php echo $match->hteam; ?></a>
			<?php 
					break;
				case 'club':
			?>
			    	<a href="<?php echo $match->hclublink; ?>">
		        	<?php echo $match->hteam; ?></a>
			<?php 
					break;
					case 'website':
			?>
			    	<a href="<?php echo $match->hurl; ?>">
		        	<?php echo $match->hteam; ?></a>
			<?php
					break;
			}
		?>

				<?php if (JRequest::getVar('badges_ondisplay') == 'default'?
							$this->settings->frontend_images:
							JRequest::getVar('badges_ondisplay') == 'yes') {?>
							<img src="<?php echo $this->settings->tbadge_folder.$match->htbadge; ?>" />
						<?php }?>
			
			:
				<?php if (JRequest::getVar('badges_ondisplay') == 'default'?
							$this->settings->frontend_images:
							JRequest::getVar('badges_ondisplay') == 'yes') {?>
							<img src="<?php echo $this->settings->tbadge_folder.$match->vtbadge; ?>" />
						<?php }?>
		<?php switch (JRequest::getVar('links_ondisplay')){ 
				case 'none':
				default:
					echo $match->vteam;
					break;
				case 'team':
			?>
			    	<a href="<?php echo $match->vlink; ?>">
		        	<?php echo $match->vteam; ?></a>
			<?php 
					break;
				case 'club':
			?>
			    	<a href="<?php echo $match->vclublink; ?>">
		        	<?php echo $match->vteam; ?></a>
			<?php 
					break;
					case 'website':
			?>
			    	<a href="<?php echo $match->vurl; ?>">
		        	<?php echo $match->vteam; ?></a>
			<?php
					break;
			}
		?>
		
		<?php if ($match->results_quantity > 0) { ?>
			<br/>
			<?php echo $match->hscore.' : '.$match->vscore; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 1) { ?>
			<br/>(
			<?php echo $match->hscore1.' : '.$match->vscore1; ?>
		<?php if ($match->results_quantity > 2) { ?>
			,&nbsp;
			<?php echo $match->hscore2.' : '.$match->vscore2; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 3) { ?>
			,&nbsp;
			<?php echo $match->hscore3.' : '.$match->vscore3; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 4) { ?>
			,&nbsp;
			<?php echo $match->hscore4.' : '.$match->vscore4; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 5) { ?>
			,&nbsp;
			<?php echo $match->hscore5.' : '.$match->vscore5; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 6) { ?>
			,&nbsp;
			<?php echo $match->hscore6.' : '.$match->vscore6; ?>
		<?php } 
		//following closing bracket of partial result
		?>
		)
		<br/>
		 <?php echo $match->description; ?>
		<?php } ?>
			</div></td>
			<?php } ?>
		</tr>
		<?php } ?>
<?php } 
else
{ ?>
<?php $r = pow( 2, count($this->tree)-1); $c = count($this->tree);?>
		<?php for($i=0;$i<$r;$i++){ ?>
		<tr>
			<?php for($j=$c-1;$j>=0;$j--){
					 $ifinttest = $i/pow(2, $c-$j-1);
					 if ($ifinttest <> (int)$ifinttest)
					 	continue;
					 $match = $this->tree[$j][$i/pow(2,(int)($c-$j-1))]; ?>
			<td rowspan="<?php echo pow(2, $c-$j-1); ?>"><div style="text-align:center;">
			<?php echo $match->formattedmatchdate; ?><br/>
				<a href="<?php echo $match->hlink; ?>"><?php echo $match->hteam; ?></a>
				<?php if (JRequest::getVar('badges_ondisplay') == 'default'?
							$this->settings->frontend_images:
							JRequest::getVar('badges_ondisplay') == 'yes') {?>
							<img src="<?php echo $this->settings->tbadge_folder.$match->htbadge; ?>" />
						<?php }?>
			
			:
				<?php if (JRequest::getVar('badges_ondisplay') == 'default'?
							$this->settings->frontend_images:
							JRequest::getVar('badges_ondisplay') == 'yes') {?>
							<img src="<?php echo $this->settings->tbadge_folder.$match->vtbadge; ?>" />
						<?php }?>
				<a href="<?php echo $match->vlink; ?>"><?php echo $match->vteam; ?></a>
		
		<?php if ($match->results_quantity > 0) { ?>
			<br/>
			<?php echo $match->hscore.' : '.$match->vscore; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 1) { ?>
			<br/>(
			<?php echo $match->hscore1.' : '.$match->vscore1; ?>
		<?php if ($match->results_quantity > 2) { ?>
			,&nbsp;
			<?php echo $match->hscore2.' : '.$match->vscore2; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 3) { ?>
			,&nbsp;
			<?php echo $match->hscore3.' : '.$match->vscore3; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 4) { ?>
			,&nbsp;
			<?php echo $match->hscore4.' : '.$match->vscore4; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 5) { ?>
			,&nbsp;
			<?php echo $match->hscore5.' : '.$match->vscore5; ?>
		<?php } ?>
		<?php if ($match->results_quantity > 6) { ?>
			,&nbsp;
			<?php echo $match->hscore6.' : '.$match->vscore6; ?>
		<?php } 
		//following closing bracket of partial result
		?>
		)
		<br/>
		 <?php echo $match->description; ?>
		<?php } ?>
			</div></td>
			<?php } ?>
		</tr>
		<?php } ?>

<?php } ?>
</table>

